home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / libtiff / tif_dumpmode.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  143 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_dumpmode.c,v 1.29 92/10/26 17:08:41 sam Rel $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library.
  31.  *
  32.  * "Null" Compression Algorithm Support.
  33.  */
  34. #include "tiffiop.h"
  35. #include <assert.h>
  36. #include <stdio.h>
  37.  
  38. /*
  39.  * Encode a hunk of pixels.
  40.  */
  41. static int
  42. DECLARE4(DumpModeEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  43. {
  44.     /*
  45.      * This may be overzealous, but avoids having to
  46.      * worry about byte alignment for the (potential)
  47.      * byte-swapping work below.
  48.      */
  49.     if (tif->tif_rawcc + cc > tif->tif_rawdatasize)
  50.         if (!TIFFFlushData1(tif))
  51.             return (-1);
  52.     while (cc > 0) {
  53.         int n;
  54.         if ((n = cc) > tif->tif_rawdatasize)
  55.             n = tif->tif_rawdatasize;
  56.         memcpy(tif->tif_rawcp, pp, n);
  57.         if (tif->tif_flags & TIFF_SWAB) {
  58.             switch (tif->tif_dir.td_bitspersample) {
  59.             case 16:
  60.                 assert((n & 3) == 0);
  61.                 TIFFSwabArrayOfShort((u_short *)tif->tif_rawcp,
  62.                     n/2);
  63.                 break;
  64.             case 32:
  65.                 assert((n & 15) == 0);
  66.                 TIFFSwabArrayOfLong((u_long *)tif->tif_rawcp,
  67.                     n/4);
  68.                 break;
  69.             }
  70.         }
  71.         tif->tif_rawcp += n;
  72.         tif->tif_rawcc += n;
  73.         pp += n;
  74.         cc -= n;
  75.         if (tif->tif_rawcc >= tif->tif_rawdatasize &&
  76.             !TIFFFlushData1(tif))
  77.             return (-1);
  78.     }
  79.     return (1);
  80. }
  81.  
  82. /*
  83.  * Decode a hunk of pixels.
  84.  */
  85. static int
  86. DECLARE4(DumpModeDecode, TIFF*, tif, u_char*, buf, u_long, cc, u_int, s)
  87. {
  88.     if (tif->tif_rawcc < cc) {
  89.         TIFFError(tif->tif_name,
  90.             "DumpModeDecode: Not enough data for scanline %d",
  91.             tif->tif_row);
  92.         return (0);
  93.     }
  94.     /*
  95.      * Avoid copy if client has setup raw
  96.      * data buffer to avoid extra copy.
  97.      */
  98.     if (tif->tif_rawcp != (char*) buf)
  99.         memcpy(buf, tif->tif_rawcp, cc);
  100.     if (tif->tif_flags & TIFF_SWAB) {
  101.         switch (tif->tif_dir.td_bitspersample) {
  102.         case 16:
  103.             assert((cc & 3) == 0);
  104.             TIFFSwabArrayOfShort((u_short *)buf, cc/2);
  105.             break;
  106.         case 32:
  107.             assert((cc & 15) == 0);
  108.             TIFFSwabArrayOfLong((u_long *)buf, cc/4);
  109.             break;
  110.         }
  111.     }
  112.     tif->tif_rawcp += cc;
  113.     tif->tif_rawcc -= cc;
  114.     return (1);
  115. }
  116.  
  117. /*
  118.  * Seek forwards nrows in the current strip.
  119.  */
  120. static int
  121. DECLARE2(DumpModeSeek, TIFF*, tif, u_long, nrows)
  122. {
  123.     tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  124.     tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  125.     return (1);
  126. }
  127.  
  128. /*
  129.  * Initialize dump mode.
  130.  */
  131. int
  132. DECLARE1(TIFFInitDumpMode, TIFF*, tif)
  133. {
  134.     tif->tif_decoderow = DumpModeDecode;
  135.     tif->tif_decodestrip = DumpModeDecode;
  136.     tif->tif_decodetile = DumpModeDecode;
  137.     tif->tif_encoderow = DumpModeEncode;
  138.     tif->tif_encodestrip = DumpModeEncode;
  139.     tif->tif_encodetile = DumpModeEncode;
  140.     tif->tif_seek = DumpModeSeek;
  141.     return (1);
  142. }
  143.